package platform_api.Controller;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import platform_api.Model.JsonMessage;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ErrorHandleController extends Controller implements ErrorController{

    @ExceptionHandler(Exception.class)
    @RequestMapping("/error")
    public JsonMessage errorHandle(HttpServletRequest request,Exception e){
        return getJsonErrorMessage(request.getAttribute("javax.servlet.error.status_code"),e.getMessage());
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}
